﻿@using GoodMan.Infrastructure.Entities.Entity;
@{
    Layout = "/Areas/WorkSpace/Views/Shared/_CollegeAdminTemplete.cshtml";
}
@section head{
<link type="text/css" rel="Stylesheet" href="/content/css/select2.css" />
}
<div id="content-header">
    <h1>
        新设排班</h1>
</div>
<div id="breadcrumb">
    <a href="#" title="Go to Home" class="tip-bottom"><i class="icon-home"></i>首页</a>
    <a href="#" class="tip-bottom">楼栋管理</a> <a href="#" class="current">新设排班</a>
</div>
<div class="container-fluid">
    <div class="row-fluid">
        <div class="span12">
            <div class="widget-box">
                <div class="widget-title">
                    <span class="icon"><i class="icon-align-justify"></i></span>
                    <h5>
                        新设排班</h5>
                </div>
                <div class="widget-content nopadding">
                    <form id="dutyform" action="/workspace/collegeadmin/newdutyset" method="post" name="regform"
                    class="form-horizontal">
                    <div class="control-group">
                        <label class="control-label">
                            排班日期</label>
                        <div class="controls" style="height:30px;">
                            <div id="setstart" class="input-append span3">
                                <input data-format="yyyy-MM-dd" type="text" name="setstart" id="txtsetstart"
                                    class="{required:true,dateISO:true}" />
                                <span class="add-on"><i class="icon-calendar" data-time-icon="icon-time" data-date-icon="icon-calendar">
                                </i></span>
                            </div>
                            <div id="setend" class="input-append span3">
                                <input data-format="yyyy-MM-dd" type="text" name="setend" id="txtsetend"
                                    class="{required:true,dateISO:true}" />
                                <span class="add-on"><i class="icon-calendar" data-time-icon="icon-time" data-date-icon="icon-calendar">
                                </i></span>
                            </div>
                            <div id="errormsg" class="span3" style="display:none;color:#b94a48; line-height:30px;"></div>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">
                            排班</label>
                        <div class="controls">
                            @{
                                List<Dormitory> list = ViewBag.Dormitory;
                                List<User> staff = ViewBag.Staff;
                                if (list != null && list.Any())
                                {
                                    foreach (var item in list)
                                    {
                                <span>@item.Name：&nbsp;&nbsp;<br />
                                    早班：
                                    <select id="sltfirst@(item.Id)" name="first@(item.Id)"  style="width: 170px">
                                    @{
                                        foreach (var user in staff)
                                            {
                                                <option value="@(user.UserName+"|"+user.RealName)">@user.RealName</option>
                                            }
                                        }
                                    </select>
                                    中班：
                                    <select id="sltmiddle@(item.Id)" name="middle@(item.Id)"  style="width: 170px">
                                    @{
                                        foreach (var user in staff)
                                            {
                                                <option value="@(user.UserName+"|"+user.RealName)">@user.RealName</option>
                                            }
                                        }
                                    </select>
                                    晚班：
                                    <select id="sltlast@(item.Id)" name="last@(item.Id)"  style="width: 170px" >
                                    @{
                                        foreach (var user in staff)
                                            {
                                                <option value="@(user.UserName+"|"+user.RealName)">@user.RealName</option>
                                            }
                                        }
                                    </select>
                                    <hr />
                                </span>
                                    }
                                }
                            }
                        </div>
                    </div>
                    <div class="form-actions">
                        <button type="submit" class="btn btn-primary">
                            保存</button>
                    </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@section tail{
    <script type="text/javascript" src="/scripts/select2.min.js"></script>
    <script type="text/javascript" src="/Scripts/bootstrap-datetimepicker.min.js"></script>
    <script type="text/javascript" src="/Scripts/jquery.validate.js"></script>
    <script type="text/javascript" src="/Scripts/jquery.metadata.js"></script>
    <script type="text/javascript">
        $(function () {
            $('#dutyform').validate({
                errorClass: "help-inline",
                errorElement: "span",
                highlight: function (element, errorClass, validClass) {
                    $(element).parents('.control-group').addClass('error');
                },
                unhighlight: function (element, errorClass, validClass) {
                    $(element).parents('.control-group').removeClass('error');
                },
                submitHandler: function (form) {
                    var start = $('#txtsetstart').val().replace(/-/g,'/');
                    var end = $('#txtsetend').val().replace(/-/g, '/');
                    if (Date.parse(end) < Date.parse(start)) {
                        alert('起始时间必须大于结束时间');
                        return false;
                    }
                    if (Date.parse(start) <= Date.parse('@DateTime.Now.ToString("yyyy/MM/dd")')) {
                        alert('起始时间必须大于今天');
                        return false;
                    }
                    if(Date.parse(end) > Date.parse('@DateTime.Now.AddDays(7).ToString("yyyy/MM/dd")')){
                        alert('最多只能排7天班');
                        return false;
                    }
                }
            });

            $('#setstart').datetimepicker({
                pickTime: false
            });
            $('#setend').datetimepicker({
                pickTime: false
            });
            $('#likDormitory').addClass('open active');
            $('select[name^="first"]').each(function () {
                $(this).select2();
            });
            $('select[name^="middle"]').each(function () {
                $(this).select2();
            });
            $('select[name^="last"]').each(function () {
                $(this).select2();
            });
        });
    </script>
}
